/**
 * FileName: MathUtils
 * Author: clark
 * Date: 2024/10/13 4:52 PM
 * Description:
 * History:
 * <author> <time> <version> <desc>
 * 作者姓名 修改时间 版本号 描述
 */
package com.sandu.facedetecter.util;

import com.huawei.hms.mlsdk.common.MLPosition;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: MathUtils
 * @Description: java类作用描述
 * @Author: clark
 * @Date: 2024/10/13 4:52 PM
 */
public class FaceMathUtils {
    public static List<Float> getEdge(List<MLPosition> points) {
        List<Float> result = new ArrayList<>();
        int mPreviewWidth = 1280;
        int mPreviewHeight = 720;

        float maxx = 0f;
        float minx = 1000f;
        float maxy = 0f;
        float miny = 1000f;
        float resultmaxx = 0f;
        float resultminx = 1000f;
        float resultmaxy = 0f;
        float resultminy = 1000f;
        for (int i = 0; i < points.size(); i++) {
            minx = Math.min(minx, points.get(i).getX());
            maxx = Math.max(maxx, points.get(i).getX());
            maxy = Math.max(maxy, points.get(i).getY());
            miny = Math.min(miny, points.get(i).getY());
        }

        resultminx = (miny / mPreviewHeight) * 2 - 1;
        resultminy = (minx / mPreviewWidth) * 2 - 1;
        resultmaxx = (maxy / mPreviewHeight) * 2 - 1;
        resultmaxy = (maxx / mPreviewWidth) * 2 - 1;

        result.add(-resultminx);
        result.add(-resultmaxx);
        result.add(resultminy);
        result.add(resultmaxy);


        return result;

    }
}
